package com.zh.util

import java.util.regex.Pattern


fun validateAndExtract(s: String): Triple<Boolean, String, String> {
    val pattern = Pattern.compile("^\\[([^\\]]+)\\]\\s*(.*)$")
    val matcher = pattern.matcher(s)

    return if (matcher.find()) {
        val content = matcher.group(1) ?: ""
        val remainder = (matcher.group(2) ?: "").trim('\'', '"')
        Triple(true, content, remainder)
    } else {
        Triple(false, "", "")
    }
}

fun parseArgs(args: Array<String>): Map<String, String> {
    // 检查是否有参数
    if (args.isEmpty()) return emptyMap()

    val argMap = args.mapNotNull {
        """^-{1,2}(.+?)=(.+)$""".toRegex().find(it)?.destructured?.let { (key, value) -> key to value }
    }.toMap()

    return argMap
}
